package com.cskaoyan.service.impl;

import com.cskaoyan.bean.bo.BrandListBo;
import com.cskaoyan.bean.pojo.MallBrand;
import com.cskaoyan.bean.pojo.MallBrandExample;
import com.cskaoyan.bean.vo.BrandListVo;
import com.cskaoyan.bean.vo.BrandVo;
import com.cskaoyan.bean.vo.MallBrandVo;
import com.cskaoyan.mapper.MallBrandMapper;
import com.cskaoyan.mapper.MallGoodsMapper;
import com.cskaoyan.service.WxBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ycb
 * @description: 品牌模块
 * @time: 2021/7/12 14:55
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    MallBrandMapper brandMapper;
    @Autowired
    MallGoodsMapper goodsMapper;

    @Override
    public BrandListVo getBrandList(BrandListBo brandListBo) {
        PageHelper.startPage(brandListBo.getPage(),brandListBo.getSize());
        List<MallBrand> mallBrands = brandMapper.selectByExample(new MallBrandExample());

        List<BrandVo> brandVos = new ArrayList<>();
        for (MallBrand mallBrand : mallBrands) {
            brandVos.add(new BrandVo(mallBrand.getDesc(),mallBrand.getFloorPrice(),mallBrand.getId(),mallBrand.getName(),mallBrand.getPicUrl()));
        }

        PageInfo<BrandVo> brandVoPageInfo = new PageInfo<>(brandVos);
        int totalPages = (int)brandVoPageInfo.getTotal();
        return new BrandListVo(brandVos,totalPages);
    }


    @Override
    public MallBrandVo getBrandDetail(Integer id) {
        MallBrand mallBrand = brandMapper.selectByPrimaryKey(id);
        return new MallBrandVo(mallBrand);
    }
}